package com.zhoujing.adapter;

import java.util.List;


import com.android.volley.RequestQueue;
import com.android.volley.toolbox.NetworkImageView;
import com.zhongxin.wymovieticket.R;
import com.zhoujing.Entity.ActityHotEntity;
import com.zhoujing.adapter.MeAdapter.ViewHolder;
import com.zhoujing.utils.ImageDownLoad;
import com.zhoujing.utils.ImageDownLoadUtils;
import com.zhoujing.utils.ImageDownload_NetworkImageView;


import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivityListitemAdapter extends BaseAdapter {

	private List<ActityHotEntity> list;
	private RequestQueue queue;
	private LayoutInflater inflater;
	private Context context;
	LruCache<String, Bitmap> lruCache;
	public ActivityListitemAdapter(Context context,List<ActityHotEntity> list,RequestQueue queue,LruCache<String, Bitmap> lruCache)
	{
		inflater=LayoutInflater.from(context);
		this.list=list ;
		this.queue=queue;
		this.context=context;
		this.lruCache=lruCache;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if (arg1==null) {
			viewHolder=new ViewHolder();
			arg1=inflater.inflate(R.layout.activity_activity_listview_item, arg2, false);
			viewHolder.activityImageView=(NetworkImageView) arg1.findViewById(R.id.activity_listitem_imageview);
			viewHolder.activitytTextView=(TextView) arg1.findViewById(R.id.activity_listitem_textview);
			arg1.setTag(viewHolder);
		}
		else {
			viewHolder=(ViewHolder) arg1.getTag();
		}
		viewHolder.activitytTextView.setText(list.get(arg0).getTitle());
		try {
			
			ImageDownload_NetworkImageView.downLoadImage(queue, context, list.get(arg0).getPicUrl(), viewHolder.activityImageView, lruCache);
			//ImageDownLoad.downLoadImage(list.get(arg0).getPicUrl(), context, queue, viewHolder.activityImageView);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return arg1;
	}

	private static class ViewHolder
	{
		NetworkImageView activityImageView;
		TextView activitytTextView;
	}
}
